home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / seabool2.zip / SOMEBOOL.PAS < prev   
Pascal/Delphi Source File  |  1990-02-01  |  5KB  |  154 lines

  1. program Somebool;{Demonstration only: run Somebool.exe}
  2. USES SEABOOL, crt;
  3.  
  4. {*********************************************************************}
  5. {sample for seabool.pas Turbo Pascal 5.5 search unit}
  6. {calls: bool_init       any_bool}
  7. {see the file seabool.doc for detailed PROGRAMMER instructions for seabool}
  8.  
  9.  
  10.  
  11. {THIS PROGRAM IS AN EXAMPLE OF THE SEABOOL IMPLEMENTATION.
  12. IT IS BY NO MEANS AN EXHAUSTIVE DEMONSTRATION, AND MAKES NO
  13. ATTEMPT TO PROVIDE THE USUAL AMENITIES OF USER EDITING KEYS
  14. OR DESIGN. IT IS NOT MEANT TO BE A USER PRODUCT}
  15.  
  16. {THE USER IS ASKED TO TYPE IN A SENTENCE.}
  17. {THE USER IS ASKED FOR A TEXT CONDITION}
  18. {THE USER IS TOLD WHETHER HIS CONDITION IS FOUND IN THE ORIGINAL SENTENCE}
  19. {OR THE USER IS TOLD THE CONDITION IS ILLOGICAL OR TOO COMPLICATED}
  20. {OR THE USER IS TOLD THE CONDITION IS LOGICALLY ALWAYS FALSE}
  21. {CRITICAL VARIABLES ARE DISCLOSED}
  22. {**********************************************************}
  23.  
  24. var {for this demo only: seabool provides other variables. see manual file
  25.        Seabool.doc for information or read the beginning of Seabool.pas
  26.         UNIT source file}
  27.  
  28.   source_string:string;{what you are searching}
  29.   target_string:string;{the text condition the user is looking for}
  30.   interface_source_string:string;{search source
  31.                             string for your search primitive}
  32.  
  33.   ch:char;{just used to read the keypress of the user in the demo}
  34.   counter:letter_type{a seabool type variable};
  35.   there_was_a_critical_one:boolean;{just used in this demo}
  36. {THIS IS THE USER DEFINED SEARCH PRIMITIVE "you" write}
  37. {NOT FAR CALL COMPILER OPTION!}
  38. {$F+}
  39. procedure my_search_procedure(var target:string;var valid:boolean);
  40.       begin
  41.         valid:= Pos(target,lowercase(interface_source_string))>0;
  42.       end{procedure my_search...};
  43. {$F-}
  44.  
  45.  
  46.  
  47. begin {MAIN DEMONSTRATION OF SEABOOL SEARCH CAPABILITY:}
  48.   clrscr;
  49.   {*************************}
  50.   {MESSAGE}
  51.   Writeln('This is a simple demonstration of Seabool Searcher');
  52.   writeln
  53.   ('It uses the identical unit provided with your programmers package');
  54.   writeln;writeln('You type in any sentence of your choice,');
  55.   writeln('then a text condition using');
  56.   writeln('and or not operators.   parentheses allowed');
  57.   writeln
  58.   ('THE PROGRAM TELLS WHETHER YOUR CONDITION WAS PRESENT IN THE SENTENCE');
  59.   writeln;Writeln('(press any key to continue, esc to exit)');
  60.    ch:=readkey;if ch=#0 then ch:=readkey;
  61.   if ch=#27 then halt;
  62.  
  63.  
  64.   {*********************DEMO DEMO DEMO DEMO of seabool.pas unit********}
  65.   REPEAT
  66.  
  67.   clrscr;
  68.   Writeln('DEMONSTRATION OF THE SEABOOL UNIT');
  69.   Writeln('PLEASE NOTE YOU don''t get any fancy editing keys!');
  70.   Writeln;
  71.   Write('Please enter any sentence (ENTER=exit)  ');
  72.   Writeln('example: I want to phone up Mary tonight');
  73.   Writeln;Writeln;
  74.   Write('>');
  75.  
  76.  
  77.  
  78.   {EXAMPLE OF SEARCH SPACE:}
  79.   Readln(source_string);
  80.   IF source_string<>'' then
  81.   BEGIN
  82.      Writeln;
  83.  
  84.      {********************************}
  85.      {GET BOOLEAN CONDITON FROM USER:}
  86.      Write('Please type in a AND   OR NOT condition.        ');
  87.      Writeln('example: phone and (mary or sue)');
  88.      Writeln;Writeln;
  89.      Write('>');
  90.      Readln(target_string);
  91.      Editstring(target_string);{Editstring is an tool of seabool}
  92.      if ((target_string='') or (target_string='exit')) then halt;
  93.      bool_init(target_string);
  94.  
  95.  
  96.  
  97.  
  98.      {************************************}
  99.      {NOW WE VALIDATE THIS target_string:}
  100.          if bool_validation_sit=2 then
  101.              Writeln('YOUR REQUEST IS TOO COMPLICATED OR NOT LOGICAL')
  102.          else
  103.          if bool_validation_sit=4 then
  104.              Writeln('YOUR REQUEST WILL NEVER BE TRUE')
  105.      ELSE {Valid user input}
  106.  
  107.         begin
  108.      {******************}
  109.      {******THE SEARCH:***********
  110.      could be a loop for many source_strings or objects}
  111.  
  112.      interface_source_string:=source_string;
  113.      if any_bool(my_search_procedure) then
  114.         Writeln('THIS CONDITION IS TRUE IN YOUR SENTENCE')
  115.      else
  116.         Writeln('THIS CONDITION WAS NOT FOUND IN YOUR SENTENCE');
  117.         end;
  118.  
  119.      {**********************************************************************}
  120.      {DEMONSTRATION OF CRITICAL VARIABLE INFO}
  121.      if ((bool_validation_sit<>2) and (bool_validation_sit<>4)) then
  122.      begin
  123.      There_was_a_critical_one:=false ;{default}
  124.      for counter:='b' to  length_object_hash_table_0 do
  125.           if bool_crit_true[counter] then
  126.                 there_was_a_critical_one:=true;
  127.      if There_was_a_critical_one then
  128.          begin
  129.           writeln;
  130.           writeln('By the way, I knew that you were looking for:');
  131.           for counter:='b' to  length_object_hash_table_0 do
  132.           if bool_crit_true[counter] then
  133.                 writeln(
  134.                 search_object_hash_table_0[counter]);
  135.           Writeln('I could have checked those word(s) in my database INDEX!');
  136.         end;
  137.      end;{DEMO OF CRITICAL VARIABLE KNOWLEDGE}
  138.  
  139.  
  140.      {*****************DEMO loop ENDING************}
  141.      writeln(chr(7));
  142.      Writeln;
  143.      Writeln
  144.      ('--------Please press any key to try it again, or Esc to END-------');
  145.      ch:=readkey;if ch=#0 then ch:=readkey;if ch=#27 then
  146.            source_string:='';
  147.      {**********************************************************************}
  148.  
  149.   END;
  150.  
  151.   UNTIL source_string='';
  152. end.
  153.  
  154.